package org.project.areader.util;

import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;

import android.content.Context;
import android.content.res.AssetManager;
import android.util.Log;

/**
 * 
 * @author robin
 * @date 2011-3-22
 * 
 */
public class Util
{

	/**
	 * 
	 * @param filePath
	 * @return
	 */
	public static String getAssetsFileString(Context context, int filePath)
	{
		InputStream is = null;
		DataInputStream dis = null;
		String text = null;
		try
		{
			AssetManager am = context.getAssets();					
			is = am.open(context.getText(filePath).toString());
			dis = new DataInputStream(is);
			byte[] buffer = new byte[is.available()];
			dis.readFully(buffer);
			text = new String(buffer, "GBK");
		}
		catch (Exception e)
		{
			Log.e(Global.TAG, e.getMessage());
		}
		finally
		{
			try
			{
				if (is != null)
					is.close();
				if (dis != null)
					dis.close();
			}
			catch (IOException e)
			{
				e.printStackTrace();
			}
		}
		return text;

	}
}
